package 栈和队列;

import java.util.LinkedList;
import java.util.Queue;

public class LC_225用队列实现栈 {

    Queue<Integer> queue1;
    Queue<Integer> queue2;
    public LC_225用队列实现栈() {
        queue1=new LinkedList<>();
        queue2=new LinkedList<>();
    }

    public void push(int x) {
        queue2.offer(x);
        while(!queue1.isEmpty())
            queue2.offer(queue1.poll());
        Queue<Integer> temp=queue1;
        queue1=queue2;
        queue2=temp;
    }
    //移除并返回栈顶元素
    public int pop() {
        return queue1.poll();
    }
    //返回栈顶元素
    public int top() {
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}
